<%--
  Created by IntelliJ IDEA.
  User: Admin
  Date: 2022/8/9
  Time: 18:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改信息页面</title>
    <script src="js/jquery-3.6.0.js"></script>
</head>
<body>
<div style="margin: auto;width: 400px">
    <h2  style="width: 450px;margin: auto;font-size: 35px">修改电池信息页面</h2>
    <table border="1px">
        <tr>
            <td>车辆类型:</td>
            <td><input type="text" value="${requestScope.powerbattery.carName}" id="carName"></td>
        </tr>
        <tr>
            <td>所属城市:</td>
            <td><input type="text" value="${requestScope.powerbattery.cityName}" id="cityName"></td>
        </tr>
        <tr>
            <td>使用单位:</td>
            <td><input type="text" value="${requestScope.powerbattery.userName}" id="userName"></td>
        </tr>
        <tr>
            <td>压差报警值:</td>
            <td><input type="text" value="${requestScope.powerbattery.pressureValue}" id="pressureValue"></td>
        </tr>
        <tr>
            <td>报警时间:</td>
            <td><input type="text" value="${requestScope.powerbattery.time}" id="time"></td>
        </tr>
        <tr>
            <td>操作:</td>
            <td><input type="button" value="修改" id="updateBut"></td>
        </tr>
    </table>
</div>
    <script>
        $(function (){
            $("#updateBut").click(function (){
                let car = $("#carName").val();
                let user = $("#userName").val();
                let city = $("#cityName").val();
                let pre = $("#pressureValue").val();
                let regDate = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
                let time = $("#time").val().trim();
                if (car==="" ||user.trim()===""||city.trim()===""||pre.trim()===""||time.trim()===""){
                    alert("请填写完整的信息")
                    return false
                }
                if (    isNaN(pre.trim())){
                    alert("压强报警值必须是数值类型")
                    return false
                }
                if (!regDate.test(time) ){
                    alert("时间函数不合法，正确格式是“yyyy-MM-dd”")
                    return false
                }
                onSub(car,user,city,pre,time,${requestScope.powerbattery.id})
            })
        })
        var onSub = function (car,user,city,pre,time,id){
            $.ajax({
                url:"powerbatteryUpdate",
                dataType:"text",
                type:"post",
                data:{
                    car:car,
                    user:user,
                    city:city,
                    pre:pre,
                    time:time,
                    id:id,
                    opr:"updateSet"
                },
                success:function (data){
                    if (data==="true"){
                        alert("修改成功");
                    }else {
                        alert("修改失败");
                    }
                    location.href="powerbatterySelect?opr=all"
                }
            })
        }
    </script>
</body>
</html>
